using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MWIS.Common;

public partial class _Default : System.Web.UI.Page
{
    MwisXml mwisXml = new MwisXml();
    MwisProducts mwisProduct = new MwisProducts();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataSet product = new DataSet();
            string categoryID = mwisXml.getCategoryID(lstpdtcategory.Text);
            product = mwisProduct.GetProducts("001");
            lstpdt.DataSource = product.Tables[0];
            lstpdt.DataBind();

            DataSet category = new DataSet();
            

            ArrayList productCategory = mwisXml.GetCategory(true);
            foreach (string productType in productCategory)
            {
                lstpdtcategory.Items.Add(productType);
            }
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        txtQuantity.Text = "";
        txtUnitPrice.Text = "";
        txtDescription.Text = "";
        
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        mwisProduct.ProductID =Convert.ToInt32(lstpdt.SelectedItem.Value); //mwisXml.getProductID(lstpdt.SelectedItem.Value);
        mwisProduct.Units = txtQuantity.Text + ","+lstunit.Text;
        mwisProduct.QtyPrice = Convert.ToSingle(txtUnitPrice.Text);
        mwisProduct.StartDate = DateTime.Today;//Convert.ToDateTime(dtpStartingPeriod.Text); //Convert.ToDateTime(lstDate.Text + "/11/" + lstYear.Text);
        mwisProduct.EndDate = DateTime.Today;//dtpEndingPeriod.SelectedDate; //Convert.ToDateTime(lstDate2.Text + "/11/" + lstYear2.Text);
        mwisProduct.Description = txtDescription.Text;
        bool result = mwisProduct.SaveWebProduct();
        lblResult.Text = result.ToString();

    }
    protected void lstpdtcategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataSet product = new DataSet();
        string categoryID = mwisXml.getCategoryID(lstpdtcategory.Text);
        product = mwisProduct.GetProducts(categoryID);
        lstpdt.DataSource = product.Tables[0];
        lstpdt.DataBind();
        //lstpdt.DataTextField = "productName";
        //lstpdt.DataValueField = "productID";
        
        //lstpdt.DataTextField = product.Tables["tblProducts"].Columns["productName"].ToString();
        

    }
}
